home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / iv / Dispatch / dispatcher.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  103 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989, 1990, 1991 Stanford University
  3.  * Copyright (c) 1991 Silicon Graphics, Inc.
  4.  *
  5.  * Permission to use, copy, modify, distribute, and sell this software and 
  6.  * its documentation for any purpose is hereby granted without fee, provided
  7.  * that (i) the above copyright notices and this permission notice appear in
  8.  * all copies of the software and related documentation, and (ii) the names of
  9.  * Stanford and Silicon Graphics may not be used in any advertising or
  10.  * publicity relating to the software without the specific, prior written
  11.  * permission of Stanford and Silicon Graphics.
  12.  * 
  13.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  14.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  15.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  16.  *
  17.  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
  18.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  21.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  22.  * OF THIS SOFTWARE.
  23.  */
  24.  
  25. /*
  26.  * Wait on multiple file descriptors until a condition occurs.
  27.  */
  28.  
  29. #ifndef dp_dispatcher_h
  30. #define dp_dispatcher_h
  31.  
  32. #include <Dispatch/enter-scope.h>
  33. #include <OS/types.h>
  34.  
  35. class FdMask;
  36. class IOHandler;
  37. class TimerQueue;
  38. class ChildQueue;
  39. struct timeval;
  40.  
  41. class Dispatcher {
  42. public:
  43.     enum DispatcherMask {
  44.     ReadMask,
  45.     WriteMask,
  46.     ExceptMask
  47.     };
  48.  
  49.     Dispatcher();
  50.     virtual ~Dispatcher();
  51.  
  52.     virtual void link(int fd, DispatcherMask, IOHandler*);
  53.     virtual IOHandler* handler(int fd, DispatcherMask) const;
  54.     virtual void unlink(int fd);
  55.  
  56.     virtual void startTimer(long sec, long usec, IOHandler*);
  57.     virtual void stopTimer(IOHandler*);
  58.  
  59.     virtual void startChild(pid_t pid, IOHandler*);
  60.     virtual void stopChild(IOHandler*);
  61.  
  62.     virtual boolean setReady(int fd, DispatcherMask);
  63.     virtual void dispatch();
  64.     virtual boolean dispatch(long& sec, long& usec);
  65.  
  66.     static Dispatcher& instance();
  67.     static void instance(Dispatcher*);
  68. protected:
  69.     virtual void attach(int fd, DispatcherMask, IOHandler*);
  70.     virtual void detach(int fd);
  71.     virtual boolean dispatch(timeval*);
  72.     virtual boolean anyReady() const;
  73.     virtual int fillInReady(FdMask&, FdMask&, FdMask&);
  74.     virtual int waitFor(FdMask&, FdMask&, FdMask&, timeval*);
  75.     virtual void notify(int, FdMask&, FdMask&, FdMask&);
  76.     virtual timeval* calculateTimeout(timeval*) const;
  77.     virtual boolean handleError();
  78.     virtual void checkConnections();
  79. protected:
  80.     int    _nfds;
  81.     FdMask* _rmask;
  82.     FdMask* _wmask;
  83.     FdMask* _emask;
  84.     FdMask* _rmaskready;
  85.     FdMask* _wmaskready;
  86.     FdMask* _emaskready;
  87.     IOHandler** _rtable;
  88.     IOHandler** _wtable;
  89.     IOHandler** _etable;
  90.     TimerQueue* _queue;
  91.     ChildQueue* _cqueue;
  92. private:
  93.     static Dispatcher* _instance;
  94.  
  95.     static void sigCLD(int);
  96. private:
  97.     /* deny access since member-wise won't work */
  98.     Dispatcher(const Dispatcher&);
  99.     Dispatcher& operator =(const Dispatcher&);
  100. };
  101.  
  102. #endif
  103.